﻿package mortal.game.scene3D.fight
{
    import Message.DB.Tables.*;
    import Message.Game.*;
    import __AS3__.vec.*;
    import com.gengine.debug.*;
    import flash.utils.*;
    import mortal.game.cache.*;
    import mortal.game.scene3D.layer3D.utils.*;
    import mortal.game.view.skill.*;

    public class FightEffectComboUtil extends Object
    {
        public var lastComboIndex:int;
        public var lastComboTime:int;
        public var lastSkill:TSkill;
        public var saveComboBeginFight:SBeginFight;
        public var saveDofights:Vector.<SDoFight>;
        private static var _instance:FightEffectComboUtil;

        public function FightEffectComboUtil()
        {
            this.saveDofights = new Vector.<SDoFight>;
            return;
        }// end function

        public function addComboFight(param1:SBeginFight, param2:TSkill, param3:Boolean = false) : Boolean
        {
            var _loc_8:int = 0;
            var _loc_4:* = Cache.instance.skill;
            var _loc_5:* = _loc_4.getComboSkill();
            if (_loc_5 == null)
            {
                return false;
            }
            var _loc_6:* = SkillUtil.getComboSkillIndex(_loc_5.tSkill, param2.skillId);
            if (_loc_6 < 0)
            {
                return false;
            }
            var _loc_7:* = getTimer();
            if (this.isNextCombo(_loc_6, this.lastComboIndex) && !param3)
            {
                _loc_8 = SkillUtil.getCoolDownTime(this.lastSkill);
                if (_loc_7 - this.lastComboTime + 30 < _loc_8)
                {
                    this.saveComboBeginFight = param1;
                    setTimeout(this.callLaterFight, this.lastComboTime + _loc_8 - _loc_7);
                    Log.debug("第" + (_loc_6 + 1) + "招延迟释放" + (this.lastComboTime + _loc_8 - _loc_7) + "毫秒");
                    return true;
                }
            }
            this.lastSkill = param2;
            this.lastComboIndex = _loc_6;
            this.lastComboTime = _loc_7;
            return false;
        }// end function

        public function callLaterFight() : void
        {
            var _loc_1:int = 0;
            if (this.saveComboBeginFight)
            {
                ThingUtil.fightUtil.beginFight(this.saveComboBeginFight, true);
                _loc_1 = 0;
                while (_loc_1 < this.saveDofights.length)
                {
                    
                    ThingUtil.fightUtil.doFightJudgeBeginFight(this.saveDofights[_loc_1]);
                    _loc_1++;
                }
                this.saveComboBeginFight = null;
                this.saveDofights.length = 0;
            }
            return;
        }// end function

        public function isNextCombo(param1:int, param2:int) : Boolean
        {
            return (param2 + 1) % 3 == param1;
        }// end function

        public function addDofight(param1:SDoFight) : Boolean
        {
            if (this.saveComboBeginFight && this.saveComboBeginFight.attackId == param1.attackId)
            {
                this.saveDofights.push(param1);
                return true;
            }
            return false;
        }// end function

        public static function get instance() : FightEffectComboUtil
        {
            if (!_instance)
            {
                _instance = new FightEffectComboUtil;
            }
            return _instance;
        }// end function

    }
}
